<template>
    <div style=" margin-top: -500px;margin-left: 400px;">
        <h2>职位名称:&emsp;{{ jobTitle }}&emsp;收到简历列表</h2>
        <div v-for="deliverResume, index in deliverResumeList" :key="deliverResume.deliver_resume_id" class="descriptions">
            <el-descriptions title="" direction="vertical" :column="3" border style="margin-bottom:50px">
                <el-descriptions-item label="用户名">
                    <el-input v-model="userList.usernameList[index]" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="用户昵称">
                    <el-input v-model="userList.nicknameList[index]" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="姓名">
                    <el-input v-model="deliverResume.full_name" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="年龄">
                    <el-input v-model="seekerList.ageList[index]" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="学历">
                    <el-input v-model="seekerList.educationList[index]" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="毕业年度">
                    <el-input v-model="seekerList.graduationYearList[index]" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="毕业院校">
                    <el-input v-model="seekerList.universityList[index]" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="简历名称">
                    <el-input v-model="deliverResume.resume_name" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="投递时间">
                    <el-tag size="medium" style="margin-top:5px">{{ format(deliverResume.create_time).format }}</el-tag>
                </el-descriptions-item>
                <el-descriptions-item label="您的回复">
                    <el-input v-if="deliverResume.enterprise_reply" v-model="deliverResume.enterprise_reply"
                        disabled></el-input>
                    <span v-else style="color:red">暂无</span>
                </el-descriptions-item>
                <el-descriptions-item label="操作">
                    <el-button type="primary"
                        @click="deliverResumeDetail(deliverResume.deliver_resume_id)">查看简历详情</el-button>
                </el-descriptions-item>
            </el-descriptions>
        </div>
        <div style="margin-top:10px;margin-left:-250px;margin-bottom:150px;">
            <div class="block">
                <el-pagination :current-page="currentPage" :page-size="pageSize" layout="total,  prev, pager, next, jumper"
                    :total="total" @current-change="handleCurrentChange">
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
import axios from 'axios';
import dateTime from '@/utils/date_time';
export default {
    data() {
        return {
            userList: { usernameList: [], nicknameList: [] },
            seekerList: { ageList: [], educationList: [], universityList: [], graduationYearList: [] },
            deliverResumeList: [],
            pageSize: 2,
            pagerCount: 0,
            total: 0,
            currentPage: 1,
            jobTitle: '',
        }
    },
    methods: {
        deliverResumeDetail(id) {
            window.localStorage.setItem("deliver_resume_id", id);
            this.$router.push({ name: 'deliver_resume_detail', params: { deliver_resume_id: id } }, () => { }, () => { });
        },
        getJobTitle() {
            let that = this;
            let id = window.localStorage.getItem("job_recruitment_id");
            if (that.$route.params.job_recruitment_id) {
                id = that.$route.params.job_recruitment_id;
            }
            axios({
                method: 'get',
                url: 'http://127.0.0.1:5000/api/job_recruitment/get_obj',
                params: {
                    job_recruitment_id: id
                },
                headers: {
                    'X-Auth-Token': window.localStorage.getItem("token")
                },
            })
                .then(function (response) {
                    console.log(response.data);
                    if (response.data.result.obj) {
                        that.jobTitle = response.data.result.obj.job_title;
                    }
                })
                .catch(function (error) {
                    console.log(error);
                })
                .then(function () {
                    // 总是会执行
                })
        },
        getUserList(user_id) {
            let that = this;
            axios({
                method: 'get',
                url: 'http://127.0.0.1:5000/api/user/get_obj',
                params: {
                    user_id: user_id
                },
                headers: {
                    'X-Auth-Token': window.localStorage.getItem("token")
                },
            })
                .then(function (response) {
                    console.log(response.data);
                    if (response.data.result.obj) {
                        that.userList.usernameList.push(response.data.result.obj.username);
                        that.userList.nicknameList.push(response.data.result.obj.nickname);
                    }
                })
                .catch(function (error) {
                    console.log(error);
                })
                .then(function () {
                    // 总是会执行
                })
        },
        getSeekerList(job_seekers_id) {
            let that = this;
            axios({
                method: 'get',
                url: 'http://127.0.0.1:5000/api/job_seekers/get_obj',
                params: {
                    job_seekers_id: job_seekers_id
                },
                headers: {
                    'X-Auth-Token': window.localStorage.getItem("token")
                },
            })
                .then(function (response) {
                    console.log(response.data);
                    if (response.data.result.obj) {
                        that.seekerList.ageList.push(response.data.result.obj.age);
                        that.seekerList.educationList.push(response.data.result.obj.education);
                        that.seekerList.universityList.push(response.data.result.obj.university_one_is_graduated_from);
                        that.seekerList.graduationYearList.push(response.data.result.obj.graduation_year);
                        that.getUserList(response.data.result.obj.user_id);
                    }

                })
                .catch(function (error) {
                    console.log(error);
                })
                .then(function () {
                    // 总是会执行
                })
        },
        handleCurrentChange(val) {
            let that = this;
            let id = window.localStorage.getItem("job_recruitment_id");
            if (that.$route.params.job_recruitment_id) {
                id = that.$route.params.job_recruitment_id;
            }
            axios({
                method: 'get',
                url: 'http://127.0.0.1:5000/api/deliver_resume/get_list',
                params: {
                    job_recruitment_id: id,
                    page: val,
                    size: that.pageSize
                },
                headers: {
                    'X-Auth-Token': window.localStorage.getItem("token")
                },
            })
                .then(function (response) {
                    console.log(response.data);
                    if (!response.data.result) {
                        that.$message.error("该职位暂没有收到简历!!!");
                        that.$router.push({ name: 'enterprise_job_list' }, () => { }, () => { });
                        return;
                    }
                    that.total = Number.parseInt(response.data.result.count);
                    that.pagerCount = that.total % that.pageSize;
                    that.deliverResumeList = response.data.result.list;
                    that.getJobTitle();
                    that.deliverResumeList.forEach(element => {
                        that.getSeekerList(element.job_seekers);
                    });
                })
                .catch(function (error) {
                    console.log(error);
                })
                .then(function () {
                    // 总是会执行
                })
        },
        format(create_time) {
            return dateTime.dateTime(create_time)
        },
    },
    created: function () {
        let that = this;
        let id = window.localStorage.getItem("job_recruitment_id");
        if (that.$route.params.job_recruitment_id) {
            id = that.$route.params.job_recruitment_id;
        }
        axios({
            method: 'get',
            url: 'http://127.0.0.1:5000/api/deliver_resume/get_list',
            params: {
                job_recruitment_id: id,
                page: that.currentPage,
                size: that.pageSize
            },
            headers: {
                'X-Auth-Token': window.localStorage.getItem("token")
            },
        })
            .then(function (response) {
                console.log(response.data);
                if (!response.data.result) {
                    that.$message.error("该职位暂没有收到简历!!!");
                    that.$router.push({ name: 'enterprise_job_list' }, () => { }, () => { });
                    return;
                }
                that.total = Number.parseInt(response.data.result.count);
                that.pagerCount = that.total % that.pageSize;
                that.deliverResumeList = response.data.result.list;
                that.getJobTitle();
                that.deliverResumeList.forEach(element => {
                    that.getSeekerList(element.job_seekers);
                });
            })
            .catch(function (error) {
                console.log(error);
            })
            .then(function () {
                // 总是会执行
            })
    },
}
</script>
<style lang="less" scoped>
.descriptions {
    width: 1400px;
}
</style>